package com.zhiyou100.review.day021.mydatagram;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * @packageName: TestOfDatagramSocket
 * @className: com.zhiyou100.review.day021.mydatagram
 * @Description: TODO UDP 测试 发送方
 * @author: yang
 * @date: 7/2/20
 */
public class TestOfDatagramSocket {
    public static void main(String[] args) throws Exception {
        DatagramSocket datagramSocket = new DatagramSocket(10086);
        // 创建一个 DatagramSocket

        byte[] bytes = "在吗？吃了吗".getBytes();
        DatagramPacket localhost = new DatagramPacket(bytes, 0, bytes.length, InetAddress.getByName("localhost"), 10000);
        // 端口和地址是发送的目标地址

        datagramSocket.send(localhost);
        // 发送给接收方

        datagramSocket.close();
        // 关闭

    }
}
